package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import com.fr.report.script.core.FArray;
import com.fr.report.script.core.FunctionHelper;

public class MAX extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 1)
      return Primitive.ERROR_NAME;
    double d = -1.797693134862316E+308D;
    for (int i = 0; i < paramArrayOfObject.length; ++i)
    {
      if (paramArrayOfObject[i] == null)
        break label47:
      d = Math.max(d, parseObject(paramArrayOfObject[i]));
    }
    label47: return FunctionHelper.parsePrimitiveDouble(d);
  }

  public Function.Type getType()
  {
    return Function.MATH;
  }

  private double parseObject(Object paramObject)
  {
    if (paramObject instanceof Number)
      return ((Number)paramObject).doubleValue();
    if (paramObject instanceof Boolean)
      return ((((Boolean)paramObject).booleanValue()) ? 1.0D : 0.0D);
    if (paramObject instanceof FArray)
    {
      FArray localFArray = (FArray)paramObject;
      double d = -1.797693134862316E+308D;
      int i = 0;
      int j = localFArray.length();
      while (i < j)
      {
        d = Math.max(d, parseObject(localFArray.elementAt(i)));
        ++i;
      }
      return d;
    }
    if (paramObject != null)
      try
      {
        return Double.parseDouble(paramObject.toString());
      }
      catch (NumberFormatException localNumberFormatException)
      {
        return 0.0D;
      }
    return 0.0D;
  }

  public String getCN()
  {
    return "MAX(number1,number2,…): 返回参数列表中的最大值。\nNumber1,number2,…:1到30个需要找出最大值的参数。\n备注:\n    参数可以是数字、空白单元格、逻辑值或数字的文本表达式。\n    如果数组或引用参数中包含可解析文本值，逻辑值，零值或空白单元格，这些值都将参与计算，而不可解析的文本值忽略不计。\n    如果参数中没有任何数字，MAX将返回0。\n示例:\nMAX(0.1,0,1.2)等于1.2。";
  }

  public String getEN()
  {
    return "MAX(number1,number2,…): Returns the largest value in a set of values.\nNumber1,number2,…  are 1 to 30 numbers for which you want to find the maximum value.\nRemarks:\n1. You can specify arguments that are numbers, empty cells, logical values, or text representations of numbers.\n2. If an argument is an array or reference, only numbers in that array or reference are used. Empty cells, logical values, or text in the array or reference are ignored.\n3. If the arguments contain no numbers, MAX returns 0 (zero).\nExample:\n   MAX(0.1,0,1.2)=1.2";
  }
}